package kyssion.leetcode.num51_100;

public class code80_删除排序数组中的重复项2 {
    public static void main(String[] args) {
        System.out.println(new code80_删除排序数组中的重复项2().removeDuplicates(
                new int[]{
                        0, 0, 0, 1, 1, 1, 2, 2
                }
        ));
    }

    public int removeDuplicates(int[] nums) {
        int num = 1;
        int speed = 0;
        for (int a = 1; a < nums.length; a++) {
            if (nums[a] == nums[a - 1]) {
                num++;
                if (num > 2) {
                    speed++;
                }else{
                    nums[a-speed]=nums[a];
                }
            } else {
                num = 1;
                nums[a - speed] = nums[a];
            }
        }
        return nums.length - speed;
    }
}
